﻿using System;

namespace Common
{
    /// <summary>
    /// 类型名称对, 即Type的拓展
    /// </summary>
    public struct TypeNamePair : IEquatable<TypeNamePair>
    {
        private readonly Type m_type;
        private readonly string m_name;
        
        public Type Type => m_type;
        public string Name => m_name;
        
        public TypeNamePair(Type type, string name)
        {
            m_type = type;
            m_name = name;
        }
        
        public TypeNamePair(Type type) : this(type, string.Empty)
        {
            
        }
        
        public override string ToString()
        {
            return string.Format("{0}.{1}", Type.FullName, Name);
        }

        public bool Equals(TypeNamePair other)
        {
            return m_type == other.m_type && m_name == other.m_name;
        }

        public override bool Equals(object obj)
        {
            return obj is TypeNamePair other && Equals(other);
        }

        public override int GetHashCode()
        {
            return HashCode.Combine(m_type, m_name);
        }
    }
}